package com.qianxun.Test.BaseTest;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.*;
import java.nio.file.Files;

public class TestBase642 {

    public static void main(String[] args) throws Exception {
        String s=TestBase642.TestBASE64Encoder();
        System.out.println(s);
        TestBase642.TestBASE64Decoder(s);
    }
    public static String TestBASE64Encoder() throws IOException {
        String s = null;
        File file = new File("C:\\Users\\user\\Desktop\\Snipaste_2019-11-07_11-18-16.png");
        byte[] bytes = Files.readAllBytes(file.toPath());
        BASE64Encoder base64Encoder = new BASE64Encoder();
        String encode = base64Encoder.encode(bytes);
        System.out.println(encode);
        return encode;
    }

    public static String TestBASE64Decoder(String s) throws Exception {
        BASE64Decoder base64Decoder = new BASE64Decoder();
        FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\\zdemo1.png"));
        fileOutputStream.write(base64Decoder.decodeBuffer(s));
        return null;
    }
}
